package cn.itcast.service.impl;


import cn.itcast.entity.PageResult;
import cn.itcast.entity.QueryPageBean;
import cn.itcast.mapper.CheckItemMapper;

import cn.itcast.service.CheckItemService;
import cn.itcast.domain.CheckItem;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;

    /**
     * PageResult     封装total(总记录数)   rows(List)
     * QueryPageBean   封装 currentpage   pagesize   queryString (condition)
     * Result         封装 flag  message  data(Object)
     * @param queryPageBean
     * @return
     */
    public PageResult getpageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();
        //当前数据绑定当前线程 会拼到sql语句后面
        PageHelper.startPage(currentPage,pageSize);

        Page<CheckItem> page = checkItemMapper.findByCondition(queryString);
        long total = page.getTotal();
        List<CheckItem> rows = page.getResult();

        return new PageResult(total,rows);
    }

    public void addData(CheckItem checkItem) {

        checkItemMapper.addData(checkItem);
    }

    public void deleteData(Integer id) {

       checkItemMapper.deleteComboCheck_GroupById(id);

       checkItemMapper.deleteDataById(id);

    }

    public void editData(CheckItem checkItem) {

        checkItemMapper.editData(checkItem);
    }

    public List<CheckItem> getAllList() {

        List<CheckItem> itemList = checkItemMapper.findAll();

        return itemList;
    }


}
